﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
//using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using Common;
using Site_Extractor;
namespace Forums_Extractor
{
	public partial class ForumsExtractorGUI : Form
	{
		BackgroundWorker _worker;
		Hashtable _forums;
		private Action<ProgressBar, int> _pbUpdate;
		private Action<string> _stUpdate;

		public ForumsExtractorGUI()
		{
			InitializeComponent();
			_forums = new Hashtable();
			_pbUpdate = new Action<ProgressBar, int>(_UpdateProgressBar);
			_stUpdate = new Action<string>(_ReportStatus);
		}

		private void workButton_Click(object sender, EventArgs e)
		{
			_worker = new BackgroundWorker();
			_worker.WorkerSupportsCancellation = true;
			_worker.WorkerReportsProgress = true;
			_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_worker_RunWorkerCompleted);
			_worker.DoWork += new DoWorkEventHandler(_worker_DoWork);
			_worker.ProgressChanged += new ProgressChangedEventHandler(_worker_ProgressChanged);
			_worker.RunWorkerAsync();
			forumsListBox.Items.Clear();
			workButton.Enabled = false;
			stopButton.Enabled = true;
		}

		void _worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
		{
			try
			{
				progressBar1.Value = e.ProgressPercentage;
				if (e.UserState is object[])
				{
					var objects = e.UserState as object[];
					_forums[objects[0]] = objects[1];					
					forumsListBox.Items.Add(objects[0]);

				}
				else
				{
				}
			}
			catch (Exception ex) { ReportError(ex.Message); }
		}

		void _worker_DoWork(object sender, DoWorkEventArgs e)
		{
			try
			{
				//var wallaForums = ForumWalla.GetAllForumLinks();
				//var tapuzForums = ForumTapuz.GetAllForumLinks();
				//var nanaForums = ForumNana.GetAllForumLinks();
				var f = CreateFresh();
				var forums = f.GetAllForumLinks();
				int count = forums.Count;
				_worker.ReportProgress(0, count);
				ReportStatus(string.Format("found {0} forum(s), extracting", count));
				
				for (int i = 0; i < count; i++)
				{
					if (_worker.CancellationPending) break;
					var msgLinks = f.GetAllMessageLinks(forums[i]);
					var msgs = new List<ForumMessage>();
					var msgsCount = msgLinks.Count;

					for (int j = 0; j < msgsCount; j++)
					{
						if (_worker.CancellationPending) break;
						var link = msgLinks[j];
						UpdateProgressBar(progressBar2, Pct(msgsCount, j + 1));
						ReportStatus(string.Format("Extracting message {0}/{1}", j + 1, msgsCount));
						msgs.Add(f.GetMessage(link.Link));
					}
					_worker.ReportProgress
						(Pct(count, i + 1), new object[] { forums[i], msgs });
				}
			}
			catch (Exception ex) { ReportError(ex.Message); }
		}

		int Pct(int total, int part)
		{
			if (total == 0) return 0;
			if (part <= 0) return 0;
			if (part > total) return 100;
			return (int)((double)part / (double)total * 100);
		}

		void _UpdateProgressBar(ProgressBar pb, int value)
		{
			pb.Value = value;
		}
		void UpdateProgressBar(ProgressBar pb, int value)
		{
			Invoke(_pbUpdate, pb, value);
		}
		void _ReportStatus(string status)
		{ 
			statusTextBox.AppendText(string.Format("{0}: {1}\r\n", DateTime.Now, status));
		}
		void ReportStatus(string status)
		{
			try { Invoke(_stUpdate, status); }
			catch { }
		}
		void ReportError(string error)
		{
			try { Invoke(_stUpdate, string.Format("Error: {0}", error)); }
			catch { }
		}

		void _worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
		{
			workButton.Enabled = true;
			stopButton.Enabled = false;
		}

		private void forumsListBox_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (forumsListBox.SelectedItem == null) return;
			var id = forumsListBox.SelectedItem;
			var msgs = _forums[id] as List<ForumMessage>;
			if (msgs == null) return;
			messagesListBox.Items.Clear();
			foreach (ForumMessage m in msgs)
			{
				messagesListBox.Items.Add(m);
			}
		}

		private void messagesListBox_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (messagesListBox.SelectedItem == null) return;
			ForumMessage msg = messagesListBox.SelectedItem as ForumMessage;
			if (msg == null) return;
			messageDateTimeTextBox.Text = msg.Date.ToString();
			messageTopicTextBox.Text = msg.Topic;
			messageTextTextBox.Text = msg.Text;
		}

		private void stopButton_Click(object sender, EventArgs e)
		{
			_worker.CancelAsync();
			ReportStatus("cancelling job ...");
		}
		private GenericForum CreateTapuz()
		{
			string _linkPrefix = "http://www.tapuz.co.il/forums2008/forumpage.aspx?forumid=";

			ForumRule rFID2 = new ForumRule(), rFID1 = new ForumRule();
			rFID2.ruleAction = RuleAction.Contains;
			rFID2.actionParams = new object[] { _linkPrefix };
			rFID1.ruleAction = RuleAction.ToLower;
			rFID1.nextRule = rFID2;

			ForumRule rFL1 = new ForumRule(), rFL2 = new ForumRule(), rFL3 = new ForumRule();
			rFL1.ruleAction = RuleAction.DownloadPage;
			rFL1.actionParams = new object[] { "utf-8" };
			rFL2.ruleAction = RuleAction.GetFromString;
			rFL2.actionParams = new object[] { "a(", ");" };
			rFL3.ruleAction = RuleAction.AddToString;
			rFL3.actionParams = new object[] { "&r=1" };
			rFL3.nextRule = rFL1;
			rFL1.nextRule = rFL2;

			ForumRule
				mDate1 = new ForumRule(), mDate2 = new ForumRule(), mDate3 = new ForumRule(),
				mText1 = new ForumRule(), mText2 = new ForumRule(), mTopic1 = new ForumRule(),
				mTopic2 = new ForumRule(), mId = new ForumRule();

			mDate1.ruleAction = RuleAction.GetFromString;
			mDate1.actionParams = new object[] { "'", "'" };
			mDate1.nextRule = mDate2;

			mDate2.ruleAction = RuleAction.FromListString;
			mDate2.actionParams = new object[] { 0 };
			mDate2.nextRule = mDate3;

			mDate3.ruleAction = RuleAction.GetDate;
			mDate3.actionParams = new object[] { "dd/MM/yy HH:mm" };

			mText1.ruleAction = RuleAction.GetFromString;
			mText1.actionParams = new object[] { "'", "'" };
			mText1.nextRule = mText2;

			mText2.ruleAction = RuleAction.FromListString;
			mText2.actionParams = new object[] { 2 };

			mTopic1.ruleAction = RuleAction.GetFromString;
			mTopic1.actionParams = new object[] { "'", "'" };
			mTopic1.nextRule = mTopic2;

			mTopic2.ruleAction = RuleAction.FromListString;
			mTopic2.actionParams = new object[] { 1 };

			mId.ruleAction = RuleAction.SubsringUntilFirst;
			mId.actionParams = new object[] { ',' };


			GenericForum f = new GenericForum();
			f.MainLink = "http://www.tapuz.co.il/forums/forumsListNew.asp";
			f.RuleForumIdentifier = rFID1;
			f.RuleMessageLinks = rFL3;
			f.RuleMessageDate = mDate1;
			f.RuleMessageDate = mDate1;
			f.RuleMessageText = mText1;
			f.RuleMessageTopic = mTopic1;
			f.RuleMessageId = mId;
			return f;
		}
		private GenericForum CreateWalla()
		{
			GenericForum f = new GenericForum();

			f.MainLink = "http://forums.walla.co.il/?w=/&all=1";
			ForumRule forumIdRule = new ForumRule(), c1 = new ForumRule(), c2 = new ForumRule(), c0 = new ForumRule();
			forumIdRule.ruleAction = RuleAction.ToLower;
			forumIdRule.nextRule = c0;
			c0.ruleAction = RuleAction.BoolAnd;
			c0.actionParams = new object[] { c1, c2 };
			c1.ruleAction = RuleAction.Contains;
			c1.actionParams = new object[] { "http://forums.walla.co.il/?w=/" };
			c2.ruleAction = RuleAction.ContainsCharCount;
			c2.actionParams = new object[] { '/', 5 };
			f.RuleForumIdentifier = forumIdRule;

			ForumRule links0 = new ForumRule(), links1 = new ForumRule(), links2 = new ForumRule(), links3 = new ForumRule();
			links0.ruleAction = RuleAction.GatherAllLinks;
			links0.actionParams = new object[] { links1 };

			links1.ruleAction = RuleAction.BoolAnd;
			links1.actionParams = new object[] { links2, links3 };
			links2.ruleAction = RuleAction.Contains;
			links2.actionParams = new object[] { "http://forums.walla.co.il/?w=/" };
			links3.ruleAction = RuleAction.ContainsCharCount;
			links3.actionParams = new object[] { '/', 6 };

			f.RuleMessageLinks = links0;

			Rule
				MessageTopicRule = new Rule("td", "class", "w3b"),
				MessageTextRule = new Rule("td", "class", "w3");
			ForumRule
				mText0 = new ForumRule(),
				mText1 = new ForumRule(),
				mText2 = new ForumRule(),
				mText3 = new ForumRule(),

				mTopic0 = new ForumRule(),
				mTopic1 = new ForumRule(),
				mTopic2 = new ForumRule(),
				mTopic3 = new ForumRule(),

				mDate0 = new ForumRule(),
				mDate1 = new ForumRule(),
				mDate2 = new ForumRule(),
				mDate3 = new ForumRule(),
				mId0 = new ForumRule();

			mText0.ruleAction = RuleAction.DownloadPage;
			mText0.actionParams = new object[] { "hebrew" };
			mText0.nextRule = mText1;
			mText1.ruleAction = RuleAction.GetNodes;
			mText1.nextRule = mText2;
			mText2.ruleAction = RuleAction.GetNodeByRule;
			mText2.actionParams = new object[] { MessageTextRule };
			mText2.nextRule = mText3;
			mText3.ruleAction = RuleAction.GetTextFromNode;

			f.RuleMessageText = mText0;

			mTopic0.ruleAction = RuleAction.DownloadPage;
			mTopic0.actionParams = new object[] { "hebrew" };
			mTopic0.nextRule = mTopic1;
			mTopic1.ruleAction = RuleAction.GetNodes;
			mTopic1.nextRule = mTopic2;
			mTopic2.ruleAction = RuleAction.GetNodeByRule;
			mTopic2.actionParams = new object[] { MessageTopicRule };
			mTopic2.nextRule = mTopic3;
			mTopic3.ruleAction = RuleAction.GetTextFromNode;

			f.RuleMessageTopic = mTopic0;

			mDate0.ruleAction = RuleAction.DownloadPage;
			mDate0.actionParams = new object[] { "hebrew" };
			mDate0.nextRule = mDate1;
			mDate1.ruleAction = RuleAction.GetFromString;
			mDate1.actionParams = new object[] { ">תאריך: ", "</td>" };
			mDate1.nextRule = mDate2;
			mDate2.ruleAction = RuleAction.FromListString;
			mDate2.actionParams = new object[] { 0 };
			mDate2.nextRule = mDate3;
			mDate3.ruleAction = RuleAction.GetDate;
			mDate3.actionParams = new object[] { "d/M/yyyy שעה: HH:mm" };

			f.RuleMessageDate = mDate0;

			mId0.ruleAction = RuleAction.SubstringFromLast;
			mId0.actionParams = new object[] { '/' };

			f.RuleMessageId = mId0;

			return f;
		}
		private GenericForum CreateNana()
		{
			GenericForum f = new GenericForum();

			f.MainLink = "http://forums.nana10.co.il/Category/?CategoryID=245&TypeID=1";

			ForumRule
				fid0 = new ForumRule(),
				fid1 = new ForumRule(),
				fid2 = new ForumRule(),
				fid3 = new ForumRule();

			fid0.ruleAction = RuleAction.ToLower;
			fid0.nextRule = fid1;
			fid1.ruleAction = RuleAction.BoolAnd;
			fid1.actionParams = new object[] { fid2, fid3 };
			fid2.ruleAction = RuleAction.NotContains;
			fid2.actionParams = new object[] { "pid" };
			fid3.ruleAction = RuleAction.Contains;
			fid3.actionParams = new object[] { "http://forums.nana10.co.il/forum/?forumid=" };
			f.RuleForumIdentifier = fid0;

			ForumRule
				fLink0 = new ForumRule(),
				fLink1 = new ForumRule(),
				fLink2 = new ForumRule(),
				fLink3 = new ForumRule(),
				fLink4 = new ForumRule();

			fLink0.ruleAction = RuleAction.Split;
			fLink0.actionParams = new object[] { '?' };
			fLink0.nextRule = fLink1;
			fLink1.ruleAction = RuleAction.FromListString;
			fLink1.actionParams = new object[] { 1 };
			fLink1.nextRule = fLink2;
			fLink2.ruleAction = RuleAction.AddStringTo;
			fLink2.actionParams = new object[] { "http://forums.nana10.co.il/Forum/MessagesList.asp?" };
			fLink2.nextRule = fLink3;
			fLink3.ruleAction = RuleAction.DownloadPage;
			fLink3.actionParams = new object[] { "utf-8" };
			fLink3.nextRule = fLink4;
			fLink4.ruleAction = RuleAction.GetFromString;
			fLink4.actionParams = new object[] { "if( iMsgAr != null )", "</script>" };
			f.RuleMessageLinks = fLink0;
			ForumRule
				mText0 = new ForumRule(),
				mText1 = new ForumRule(),
				mText2 = new ForumRule(),
				mText3 = new ForumRule(),
				mText4 = new ForumRule(),
				mText5 = new ForumRule(),
				mText6 = new ForumRule(),
				mText7 = new ForumRule();

			mText0.ruleAction = RuleAction.RemoveChars;
			mText0.actionParams = new object[] { '\r', '\n', '\t' };
			mText0.nextRule = mText1;
			mText1.ruleAction = RuleAction.GetFromString;
			mText1.actionParams = new object[] { "pDT(", ");" };
			mText1.nextRule = mText2;
			mText2.ruleAction = RuleAction.FromListString;
			mText2.actionParams = new object[] { 0 };
			mText2.nextRule = mText3;
			mText3.ruleAction = RuleAction.GetFromString;
			mText3.actionParams = new object[] { "'", "'," };
			mText3.nextRule = mText4;
			mText4.ruleAction = RuleAction.If;
			mText4.actionParams = new object[] { mText5, mText6, mText7 };
			mText5.ruleAction = RuleAction.CountIs;
			mText5.actionParams = new object[] { 8 };
			mText6.ruleAction = RuleAction.FromListString;
			mText6.actionParams = new object[] { 7 };
			mText7.ruleAction = RuleAction.FromListString;
			mText7.actionParams = new object[] { 6 };

			f.RuleMessageText = mText0;

			ForumRule
				mTopic0 = new ForumRule(),
				mTopic1 = new ForumRule(),
				mTopic2 = new ForumRule(),
				mTopic3 = new ForumRule(),
				mTopic4 = new ForumRule(),
				mTopic5 = new ForumRule(),
				mTopic6 = new ForumRule(),
				mTopic7 = new ForumRule();

			mTopic0.ruleAction = RuleAction.RemoveChars;
			mTopic0.actionParams = new object[] { '\r', '\n', '\t' };
			mTopic0.nextRule = mTopic1;
			mTopic1.ruleAction = RuleAction.GetFromString;
			mTopic1.actionParams = new object[] { "pDT(", ");" };
			mTopic1.nextRule = mTopic2;
			mTopic2.ruleAction = RuleAction.FromListString;
			mTopic2.actionParams = new object[] { 0 };
			mTopic2.nextRule = mTopic3;
			mTopic3.ruleAction = RuleAction.GetFromString;
			mTopic3.actionParams = new object[] { "'", "'," };
			mTopic3.nextRule = mTopic4;
			mTopic4.ruleAction = RuleAction.If;
			mTopic4.actionParams = new object[] { mTopic5, mTopic6, mTopic7 };
			mTopic5.ruleAction = RuleAction.CountIs;
			mTopic5.actionParams = new object[] { 8 };
			mTopic6.ruleAction = RuleAction.FromListString;
			mTopic6.actionParams = new object[] { 6 };
			mTopic7.ruleAction = RuleAction.FromListString;
			mTopic7.actionParams = new object[] { 5 };

			f.RuleMessageTopic = mTopic0;

			ForumRule
				mDate0 = new ForumRule(),
				mDate1 = new ForumRule(),
				mDate2 = new ForumRule(),
				mDate3 = new ForumRule(),
				mDate4 = new ForumRule(),
				mDate5 = new ForumRule();

			mDate0.ruleAction = RuleAction.RemoveChars;
			mDate0.actionParams = new object[] { '\r', '\n', '\t' };
			mDate0.nextRule = mDate1;
			mDate1.ruleAction = RuleAction.GetFromString;
			mDate1.actionParams = new object[] { "pDT(", ");" };
			mDate1.nextRule = mDate2;
			mDate2.ruleAction = RuleAction.FromListString;
			mDate2.actionParams = new object[] { 0 };
			mDate2.nextRule = mDate3;
			mDate3.ruleAction = RuleAction.GetFromString;
			mDate3.actionParams = new object[] { "'", "'," };
			mDate3.nextRule = mDate4;
			mDate4.ruleAction = RuleAction.FromListString;
			mDate4.actionParams = new object[] { 1 };
			mDate4.nextRule = mDate5;
			mDate5.ruleAction = RuleAction.GetDate;
			mDate5.actionParams = new object[] { "HH:mm dd/MM/yy" };

			f.RuleMessageDate = mDate0;

			ForumRule
				mId0 = new ForumRule(),
				mId1 = new ForumRule(),
				mId2 = new ForumRule(),
				mId3 = new ForumRule(),
				mId4 = new ForumRule(),
				mId5 = new ForumRule(),
				mId6 = new ForumRule();

			mId0.ruleAction = RuleAction.RemoveChars;
			mId0.actionParams = new object[] { '\r', '\n', '\t' };
			mId0.nextRule = mId1;
			mId1.ruleAction = RuleAction.If;
			mId1.actionParams = new object[] { mId2, mId3, mId4 };
			mId2.ruleAction = RuleAction.Contains;
			mId2.actionParams = new object[] { "iMsgAr[iMsgAr.length-1][\"ID\"]=" };
			mId3.ruleAction = RuleAction.GetFromString;
			mId3.actionParams = new object[] { "iMsgAr[iMsgAr.length-1][\"ID\"]=", ";" };
			mId3.nextRule = mId5;
			mId5.ruleAction = RuleAction.FromListString;
			mId5.actionParams = new object[] { 0 };
			mId4.ruleAction = RuleAction.GetFromString;
			mId4.actionParams = new object[] { "oCurrNode=pAN(oCurrNode,", ");" };
			mId4.nextRule = mId6;
			mId6.ruleAction = RuleAction.FromListString;
			mId6.actionParams = new object[] { 0 };

			f.RuleMessageId = mId0;

			return f;
		}
		private GenericForum CreateFresh()
		{
			GenericForum f = new GenericForum();

			f.MainLink = "http://www.fresh.co.il/";
			ForumRule
				fid0 = new ForumRule(),
				fid1 = new ForumRule(),
				fid2 = new ForumRule(),
				fid3 = new ForumRule(),
				fid4 = new ForumRule(),
				fid5 = new ForumRule();
			fid0.ruleAction = RuleAction.BoolAnd;
			fid0.actionParams = new object[] { fid1, fid2 };
			fid1.ruleAction = RuleAction.ToLower;
			fid1.nextRule = fid5;
			fid5.ruleAction = RuleAction.Contains;
			fid5.actionParams = new object[] { "/forumdisplay.php?f=" };
			fid2.ruleAction = RuleAction.SubstringFromLast;
			fid2.actionParams = new object[] { '=' };
			fid2.nextRule = fid3;
			fid3.ruleAction = RuleAction.ToInt;
			fid3.nextRule = fid4;
			fid4.ruleAction = RuleAction.GreaterThan;
			fid4.actionParams = new object[] { 11 };

			f.RuleForumIdentifier = fid0;

			ForumRule
				fLink0 = new ForumRule(),
				fLink1 = new ForumRule(),
				fLink2 = new ForumRule(),
				fLink3 = new ForumRule(),
				fLink4 = new ForumRule(),
				fLink5 = new ForumRule();

			fLink0.ruleAction = RuleAction.If;
			fLink0.actionParams = new object[] { fLink1, fLink2, fLink3 };
			fLink1.ruleAction = RuleAction.Contains;
			fLink1.actionParams = new object[] { "vBulletin" };
			fLink2.ruleAction = RuleAction.GatherAllLinks;
			fLink2.actionParams = new object[] { fLink4 };
			fLink4.ruleAction = RuleAction.Contains;
			fLink4.actionParams = new object[] { "/showthread.php?goto=lastpost&t=" };
			fLink3.ruleAction = RuleAction.SubstringFromLast;
			fLink3.actionParams = new object[] { '?' };
			fLink3.nextRule = fLink5;
			fLink5.ruleAction = RuleAction.AddStringTo;
			fLink5.actionParams = new object[] { "http://www.fresh.co.il/vBulletin/forumdisplay.php?" };
			fLink5.nextRule = fLink2;

			f.RuleMessageLinks = fLink0;

			ForumRule
				mText0 = new ForumRule(),
				mText1 = new ForumRule(),
				mText2 = new ForumRule(),
				mText3 = new ForumRule(),
				mText4 = new ForumRule(),
				mText5 = new ForumRule(),
				mText6 = new ForumRule(),
				mText7 = new ForumRule();


			mText0.ruleAction = RuleAction.SubstringFromLast;
			mText0.actionParams = new object[] { '?' };
			mText0.nextRule = mText1;
			mText1.ruleAction = RuleAction.AddStringTo;
			mText1.actionParams = new object[] { "http://www.fresh.co.il/vBulletin/showthread.php?" };
			mText1.nextRule = mText2;

			mText2.ruleAction = RuleAction.DownloadPage;
			mText2.actionParams = new object[] { "hebrew" };
			mText2.nextRule = mText3;
			mText3.ruleAction = RuleAction.GetNodes;
			mText3.nextRule = mText4;
			mText4.ruleAction = RuleAction.GetNodeByRule;
			mText4.actionParams = new object[] { new Rule("blockquote", "", "") };
			mText4.nextRule = mText5;
			mText5.ruleAction = RuleAction.GetTextFromNode;
			mText5.actionParams = new object[] { true };

			f.RuleMessageText = mText0;

			ForumRule
				mTopic0 = new ForumRule(),
				mTopic1 = new ForumRule(),
				mTopic2 = new ForumRule(),
				mTopic3 = new ForumRule(),
				mTopic4 = new ForumRule(),
				mTopic5 = new ForumRule(),
				mTopic6 = new ForumRule(),
				mTopic7 = new ForumRule();

			mTopic0.ruleAction = RuleAction.SubstringFromLast;
			mTopic0.actionParams = new object[] { '?' };
			mTopic0.nextRule = mTopic1;
			mTopic1.ruleAction = RuleAction.AddStringTo;
			mTopic1.actionParams = new object[] { "http://www.fresh.co.il/vBulletin/showthread.php?" };
			mTopic1.nextRule = mTopic2;

			mTopic2.ruleAction = RuleAction.DownloadPage;
			mTopic2.actionParams = new object[] { "hebrew" };
			mTopic2.nextRule = mTopic3;
			mTopic3.ruleAction = RuleAction.GetNodes;
			mTopic3.nextRule = mTopic4;
			mTopic4.ruleAction = RuleAction.GetNodeByRule;
			mTopic4.actionParams = new object[] { new Rule("span", "style", "font-family: arial; font-weight: bold; font-size: 16px; color: Black;") };
			mTopic4.nextRule = mTopic5;
			mTopic5.ruleAction = RuleAction.GetTextFromNode;
			mTopic5.actionParams = new object[] { true };


			f.RuleMessageTopic = mTopic0;

			ForumRule
				mDate0 = new ForumRule(),
				mDate1 = new ForumRule(),
				mDate2 = new ForumRule(),
				mDate3 = new ForumRule(),
				mDate4 = new ForumRule(),
				mDate5 = new ForumRule(),
				mDate6 = new ForumRule();

			Rule
				dateRule0 = new Rule("td", "class", "thead"),
				dateRule1 = new Rule("div", "class", "normal");
			dateRule0.Rules.Add(dateRule1);

			mDate0.ruleAction = RuleAction.SubstringFromLast;
			mDate0.actionParams = new object[] { '?' };
			mDate0.nextRule = mDate1;
			mDate1.ruleAction = RuleAction.AddStringTo;
			mDate1.actionParams = new object[] { "http://www.fresh.co.il/vBulletin/showthread.php?" };
			mDate1.nextRule = mDate2;

			mDate2.ruleAction = RuleAction.DownloadPage;
			mDate2.actionParams = new object[] { "hebrew" };
			mDate2.nextRule = mDate3;
			mDate3.ruleAction = RuleAction.GetFromString;
			mDate3.actionParams = new object[] { "ן\" border=\"0\" /></a>", "<" };
			mDate3.nextRule = mDate4;
			mDate4.ruleAction = RuleAction.FromListString;
			mDate4.actionParams = new object[] { 0 };
			mDate4.nextRule = mDate5;
			mDate5.ruleAction = RuleAction.RemoveChars;
			mDate5.actionParams = new object[] { '\r', '\n', '\t' };
			mDate5.nextRule = mDate6;
			mDate6.ruleAction = RuleAction.GetDate;
			mDate6.actionParams = new object[] { "dd-MM-yyyy, HH:mm" };

			f.RuleMessageDate = mDate0;

			ForumRule
				mId0 = new ForumRule(),
				mId1 = new ForumRule(),
				mId2 = new ForumRule(),
				mId3 = new ForumRule(),
				mId4 = new ForumRule(),
				mId5 = new ForumRule(),
				mId6 = new ForumRule();

			// http://www.fresh.co.il/vBulletin/showthread.php?p=3269285#goto_threadsearch


			mId0.ruleAction = RuleAction.SubstringFromLast;
			mId0.actionParams = new object[] { '?' };
			mId0.nextRule = mId1;
			mId1.ruleAction = RuleAction.AddStringTo;
			mId1.actionParams = new object[] { "http://www.fresh.co.il/vBulletin/showthread.php?" };
			mId1.nextRule = mId2;
			mId2.ruleAction = RuleAction.DownloadPage;
			mId2.actionParams = new object[] { "hebrew" };
			mId2.nextRule = mId3;
			mId3.ruleAction = RuleAction.GetFromString;
			mId3.actionParams = new object[] { "id=\"post", "\"" };
			mId3.nextRule = mId4;
			mId4.ruleAction = RuleAction.FromListString;
			mId4.actionParams = new object[] { 2 };

			f.RuleMessageId = mId0;

			return f;
		}
	}
}
